import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app.module';

import * as cookieParser from 'cookie-parser'
import * as session from 'express-session'
import { GlobalExceptionFilter } from './filter/api-param.filter';
import { HttpException, ValidationPipe } from '@nestjs/common';
import { WsAdapter } from '@nestjs/platform-ws';
import { WsAdapterExtra } from './ws/ws.adapter.ext';


async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);

  app.useGlobalFilters(new GlobalExceptionFilter<HttpException>())
  app.useGlobalPipes(new ValidationPipe())

  // Websocket适配器
  app.useWebSocketAdapter(new WsAdapterExtra(app));
  
  // 使用cookie中间件
  app.use(cookieParser())
  // 使用session中间件
  app.use(session({ secret: 'keyboard cat',resave:false, cookie: { maxAge: 60000,httpOnly:false },saveUninitialized:true}))

  await app.listen(10086);
}
bootstrap();
